package com.atguigu.gulimallcart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author houChen
 * @date 2022/1/4 23:25
 * @Description:
 */
public class Cart {

    List<CartItem> items;
    private Integer countNum;       //商品数量
    private Integer countType;      //商品类型数量
    private BigDecimal totalAmount;
    private BigDecimal reduce = new BigDecimal(0.00d);

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        countNum = 0 ;
        if (items!=null && items.size()>0){
            for (CartItem item : items) {
                countNum+= item.getCount();
            }
        }
        return countNum;
    }


    public Integer getCountType() {
        countType = 0 ;
        if (items!=null && items.size()>0){
            for (CartItem item : items) {
                countType+= 1;
            }
        }
        return countType;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal(0d);
        if (items!=null && items.size()>0){
            for (CartItem item : items) {
                if(item.getCheck()){
                    BigDecimal totalPrice = item.getTotalPrice();
                    amount = amount.add(totalPrice);
                }
            }
        }
        return amount.subtract(this.getReduce());
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}